import { WeApp } from '../../../common/common';
import httpClient from '../../../common/http-client';
import { config } from '../../../etc/config';
import wxService from '../../../common/wxService';
import { OrderDetail } from '../../../model/order';
import tools from '../../../common/tools'
import { MlcEnum } from '../../../model/enum'
import utils from '../../../utils/utils'

const app: WeApp = getApp() as WeApp;
interface PaymentSuccessPageData {

}
interface PaymentSuccessPage extends IPage {
}

class PaymentSuccessPage {
	private id;
	onLoad(option) {
		this.id = option.id;
		this.loadData();
	}

	public loadData() {
		httpClient.get<OrderDetail>(tools.buildUrl(config.order.order_details, {
			'id': this.id
		}))
			.then((res) => {
				if (res.succeed) {
					const date = res.value.consignee["sendTime"];
					if (date) {
						res.value.consignee["sendTime"] = utils.formatTime(new Date(date))
					}
					this.setData({
						'order': res.value,
						'statusStr': MlcEnum.OrderStauts[res.value.status]
					});
				} else {
					wxService.navigateBack();
				}
			});
	}

	onUnload() {
		debugger
		wxService.redirectTo(tools.buildUrl('/pages/order/detail/index', { id: this.id }));
	}
}

Page(new PaymentSuccessPage());
